//Copyright (C) 2012 Chirila Alexandru
//This file is part of Mirror FTP
//
//Mirror FTP is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//Mirror FTP is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with Mirror FTP.  If not, see <http://www.gnu.org/licenses/>.

#ifndef VIEW_H_
#define VIEW_H_

//#include <gtkmm.h>

#include "ftp.h"
#include "file_struct.h"
#include "observer.h"
#include "license.h"

#include <glibmm.h>
#include <glib.h>
/**
 * Manages the view of the Mirror Ftp Application
 */
class view : public Gtk::Window,observer{
private:
	ftp conn;			///<current connection
	string path;		///<current path
public:
	view();
	virtual ~view();

private:
	//drawing view
	void draw_view();
	void prep_view();
	void draw_dialogs();
	void show_view();
	void connect_signals();
	void draw_toolbar();

protected: //signals

	//Tree View
	bool fls_dbl_click(GdkEvent *ev);

	//main buttons
	void btn_connect();
	void btn_logout();
	void btn_refr();
	void btn_load();
	void btn_down();
	void btn_about();
	void btn_open();
	void btn_about_server();
	void btn_close_about_server(){about_server_dialog.hide();};

	//progress view dialog buttons
	void btn_prog_ok();
	void btn_prog_cancel();

	//info view dialog buttons
	void btn_info_yes();
	void btn_info_no();
	void btn_info_save();

	string choose_file(int t);

	void btn_close_about(){about.hide();};

private:
	//notifiers
	void pulse_progress(long long time,int speed,long long eta);
	void file_progress(string file);
	void reset_progress();
	void append_status(string x);
	void clear_status();
	void list();

private: //Widgets
	file_struct files;

	//Scrolling
	Gtk::ScrolledWindow st_scroll;
	Gtk::ScrolledWindow fl_scroll;
	Gtk::ScrolledWindow about_server_scroll;

	//TextView
	Gtk::TextView status;
	Glib::RefPtr<Gtk::TextBuffer> st_buff;

	Gtk::TextView about_server;
	Glib::RefPtr<Gtk::TextBuffer> about_server_buff;

	//Progress bar
	Gtk::ProgressBar progress;


	//Toolbar
	Glib::RefPtr<Gtk::UIManager> ui_manager;
	Glib::RefPtr<Gtk::ActionGroup> action_group;
	Gtk::Widget* toolbar;

	//Buttons
	Gtk::Button prog_ok_btn;
	Gtk::Button prog_cancel_btn;
	Gtk::Button info_yes_btn;
	Gtk::Button info_no_btn;
	Gtk::Button info_save_btn;
	Gtk::Button about_server_btn;

	//Radio
	Gtk::RadioButton::Group data_group;
	Gtk::RadioButton::Group list_group;
	Gtk::RadioButton active_radio;
	Gtk::RadioButton passive_radio;
	Gtk::RadioButton normal_list_radio;
	Gtk::RadioButton machine_list_radio;

	//Label
	Gtk::Label h_lbl;
	Gtk::Label u_lbl;
	Gtk::Label p_lbl;
	Gtk::Label prog_file_lbl;
	Gtk::Label prog_speed_lbl;
	Gtk::Label prog_time_lbl;
	Gtk::Label prog_eta_lbl;
	Gtk::Label info_msg_lbl;

	//Entry
	Gtk::Entry server_entry;
	Gtk::Entry port_entry;
	Gtk::Entry user_entry;
	Gtk::Entry pass_entry;

	//Boxes
	Gtk::Box main_box;
	Gtk::Box ctrl_box;
	Gtk::Box host_box;
	Gtk::Box data_box;
	Gtk::Box list_box;
	Gtk::Box refr_box;
	Gtk::Box server_box;

	//Panned and Frames
	Gtk::Paned main_horz;
	Gtk::Paned main_vert;
	Gtk::Frame host_frame;
	Gtk::Frame data_frame;
	Gtk::Frame refr_frame;
	Gtk::Frame time_frame;
	Gtk::Frame list_frame;

	//Dialog
	Gtk::Dialog prog;
	Gtk::AboutDialog about;
	Gtk::Dialog about_server_dialog;

	//Adjusment and spin
	Glib::RefPtr<Gtk::Adjustment> refr_rate_adj;
	Gtk::SpinButton refr_rate_btn;
	Glib::RefPtr<Gtk::Adjustment> time_out_adj;
	Gtk::SpinButton time_out_btn;

	//InfoBar
	Gtk::InfoBar info;
};

#endif /* VIEW_H_ */
